package fr.charlott.view;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import fr.charlott.business.dto.CategorieDTO;
import fr.charlott.business.service.CategorieService;

@Component("listeCategorieControler")
@Scope("view")
public class ListeCategorieControler extends CharlottControler {

	private static final long serialVersionUID = 2465999191538831539L;

	private List<CategorieDTO> categories = new ArrayList<CategorieDTO>();

	private CategorieService categorieService;
	
	private CategorieDTO selectedCategorie;

	public ListeCategorieControler() {
		super();
	}

	@Autowired(required = true)
	public ListeCategorieControler(CategorieService categorieService) {
		this();
		this.categorieService = categorieService;
		
		// Initialisation des categories
		categories = categorieService.chargerToutesLesCategories();
	}

	// actions
	public String supprimerCategorie() {
		categorieService.supprimerCategorie(selectedCategorie);
		return "gestionCategories";
	}

	// getters - setters

	public List<CategorieDTO> getCategories() {
		return categories;
	}

	public CategorieDTO getSelectedCategorie() {
		return selectedCategorie;
	}

	public void setSelectedCategorie(CategorieDTO selectedCategorie) {
		this.selectedCategorie = selectedCategorie;
	}

}
